package com.hrz.datasync.repository.primary;

import com.hrz.datasync.pojo.primary.JobAndTriggerDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @作  者: 侯建军
 * @日  期: 2018/11/06 16:43:18
 * @描  述: PagingAndSortingRepository<ImTeacher, Integer>,JpaSpecificationExecutor
 */
@Repository
public interface JobAndTriggerRepository  extends JpaRepository<JobAndTriggerDto, Integer>{
    /**
     *
     * 功能描述:
     * 查询任务与触发器详细数据，参数为分页
     * @参  数:
     * @返  回:
     * @作  者: 侯建军
     * @日  期: 2018/11/06 04:52:23
     */
     @Query(value = "SELECT jd.JOB_NAME AS jobName,jd.DESCRIPTION AS jobDescription,jd.JOB_GROUP AS jobGroupName,jd.JOB_CLASS_NAME AS jobClassName," +
             " t.TRIGGER_NAME AS triggerName," +
             " t.TRIGGER_GROUP AS triggerGroupName," +
             " FROM_UNIXTIME(t.PREV_FIRE_TIME/1000,'%Y-%m-%d %T') AS prevFireTime," +
             " FROM_UNIXTIME(t.NEXT_FIRE_TIME/1000,'%Y-%m-%d %T') AS nextFireTime," +
             " ct.CRON_EXPRESSION AS cronExpression, " +
             " t.TRIGGER_STATE AS triggerState FROM" +
             "  qrtz_job_details jd JOIN qrtz_triggers t JOIN qrtz_cron_triggers ct ON jd.JOB_NAME = t.JOB_NAME AND t.TRIGGER_NAME = ct.TRIGGER_NAME AND t.TRIGGER_GROUP = ct.TRIGGER_GROUP" +
             " limit ?1,?2",nativeQuery=true)
     List<Map<String,Object>> getJobAndTriggerDetails(int currentPage, int pageSize);
    /**
     *
     * 功能描述: 
     * 获取任务与触发器数据
     * @参  数:
     * @返  回: 
     * @作  者: 侯建军
     * @日  期: 2018/11/06 04:53:06
     */
//    Map<String,Object> getJobAndTriggerDto();
}
